 package com.pansky.integration.modules.sys.interceptor;
 
 import com.pansky.integration.common.service.BaseService;
 import com.pansky.integration.common.utils.DateUtils;
 import java.text.SimpleDateFormat;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.slf4j.Logger;
 import org.springframework.core.NamedThreadLocal;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
 
 public class LogInterceptor extends BaseService
   implements HandlerInterceptor
 {
   private static final ThreadLocal<Long> startTimeThreadLocal = new NamedThreadLocal("ThreadLocal StartTime");
 
   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
     throws Exception
   {
     if (this.logger.isDebugEnabled()) {
       long beginTime = System.currentTimeMillis();
       startTimeThreadLocal.set(Long.valueOf(beginTime));
       this.logger.debug("开始计时: {}  URI: {}", new SimpleDateFormat("hh:mm:ss.SSS").format(Long.valueOf(beginTime)), request.getRequestURI());
     }
 
     return true;
   }
 
   public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
     throws Exception
   {
     if (modelAndView != null)
       this.logger.info("ViewName: " + modelAndView.getViewName());
   }
 
   public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
     throws Exception
   {
     if (this.logger.isDebugEnabled()) {
       long beginTime = ((Long)startTimeThreadLocal.get()).longValue();
       long endTime = System.currentTimeMillis();
       this.logger.debug("计时结束：{}  耗时：{}  URI: {}  最大内存: {}m  已分配内存: {}m  已分配内存中的剩余空间: {}m  最大可用内存: {}m", new Object[] { new SimpleDateFormat("hh:mm:ss.SSS").format(Long.valueOf(endTime)), DateUtils.formatDateTime(endTime - beginTime), request.getRequestURI(), Long.valueOf(Runtime.getRuntime().maxMemory() / 1024L / 1024L), Long.valueOf(Runtime.getRuntime().totalMemory() / 1024L / 1024L), Long.valueOf(Runtime.getRuntime().freeMemory() / 1024L / 1024L), Long.valueOf((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory()) / 1024L / 1024L) });
     }
   }
 }




